
import { _decorator, Component, Node, Enum, Collider } from 'cc';
const { ccclass, property } = _decorator;

enum PhyGroup {
    Default = 1 << 0,
    Cat = 1 << 1,
    Obstacle = 1 << 2,
    Fish = 1 << 3,
}

Enum(PhyGroup)

@ccclass('Mask')
class Mask {
    @property({ type: PhyGroup })
    mask: PhyGroup = PhyGroup.Default;
}

@ccclass('PhyMask')
export class PhyMask extends Component {

    @property({ type: PhyGroup })
    group: PhyGroup = PhyGroup.Default

    @property(Mask)
    mask: Mask[] = [];

    start() {
        //设置分组
        this.setGroup();
        //设置掩码
        this.setMask();
    }

    setGroup() {
        this.node.getComponent(Collider)?.setGroup(this.group)
    }

    setMask() {
        let mask = PhyGroup.Default;
        for (const maskData of this.mask) {
            mask += maskData.mask;
        }
        this.node.getComponent(Collider)?.setMask(mask)
    }


}
